//
//  SSGoodsListCell.m
//  textDemo
//
//  Created by Esther on 2017/2/21.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSGoodsListCell.h"
#import <UIImageView+WebCache.h>

@interface SSGoodsListCell()
@property(nonatomic, strong) UIImageView *countryImageView;
@property(nonatomic, strong) UIImageView *goodsImageView;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *priceLabel;
@end

@implementation SSGoodsListCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.goodsImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.priceLabel];
        
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    #pragma mark - 约束
    __weak typeof (self) weakSelf = self;
    [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(0, 0, 80, 0));
        
    }];
    
//    [_countryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(weakSelf.mas_top).offset(10);
//        make.left.equalTo(weakSelf.mas_left).offset(10);
//        make.size.mas_equalTo(CGSizeMake(22, 16));
//    }];
//    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.goodsImageView.mas_bottom).offset(10);
        make.left.equalTo(weakSelf.mas_left).offset(10);
        make.right.equalTo(weakSelf.mas_right).offset(-10);
        make.height.equalTo(@40);
        
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(10);
        make.left.equalTo(weakSelf.mas_left).offset(10);
        make.right.equalTo(weakSelf.mas_right).offset(-10);
        make.height.equalTo(@16);
    }];
    
}
- (void)setPromotion:(SSPromotion *)promotion{
    _promotion = promotion;
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:promotion.img] placeholderImage:[UIImage imageNamed:@"iconImage"]];
    self.titleLabel.text = promotion.brand_name;
    self.priceLabel.text = [NSString stringWithFormat:@"%.2f",promotion.partner_price];
    
//    [self.countryImageView sd_setImageWithURL:[NSURL URLWithString:promotion.pre_img] placeholderImage:[UIImage imageNamed:@"iconImage"]];
    
    NSLog(@"%@",promotion);
    
}


#pragma mark -
#pragma mark - 懒加载

- (UIImageView *)countryImageView{
    if (!_countryImageView) {
        _countryImageView = [[UIImageView alloc] init];
        
    }
    return _countryImageView;
}

- (UIImageView *)goodsImageView{
    if (!_goodsImageView) {
        _goodsImageView = [[UIImageView alloc] init];
        
    }
    return _goodsImageView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14.0];
        _titleLabel.numberOfLines = 2;
        
    }
    return _titleLabel;
}

- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        
    }
    return _priceLabel;
}
@end
